package com.lighthouse.doc.search.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.lighthouse.doc.search.domain.KnowledgeDocSearch;
import com.lighthouse.doc.search.service.IKnowledgeDocSearchService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * searchController
 * 
 * @author ysz
 * @date 2023-08-15
 */
@RestController
@RequestMapping("/knowledge/search")
public class KnowledgeDocSearchController extends BaseController
{
    @Autowired
    private IKnowledgeDocSearchService knowledgeDocSearchService;

    /**
     * 查询search列表
     */
    @PreAuthorize("@ss.hasPermi('lighthouse:doc:list')")
    @GetMapping("/list")
    public TableDataInfo list(KnowledgeDocSearch knowledgeDocSearch)
    {
        List<KnowledgeDocSearch> list = knowledgeDocSearchService.selectKnowledgeDocSearchList(knowledgeDocSearch);
        return getDataTable(list);
    }

    /**
     * 查询search列表
     */
    @PreAuthorize("@ss.hasPermi('knowledge:doc:list')")
    @GetMapping("/list/history")
    public TableDataInfo history(KnowledgeDocSearch knowledgeDocSearch)
    {
        List<KnowledgeDocSearch> list = knowledgeDocSearchService.selectKnowledgeDocSearchListHistory(knowledgeDocSearch);
        return getDataTable(list);
    }

    /**
     * 查询search列表
     */
    @PreAuthorize("@ss.hasPermi('knowledge:doc:list')")
    @GetMapping("/list/hot")
    public TableDataInfo hot(KnowledgeDocSearch knowledgeDocSearch)
    {
        List<KnowledgeDocSearch> list = knowledgeDocSearchService.selectKnowledgeDocSearchListHot(knowledgeDocSearch);
        return getDataTable(list);
    }

    /**
     * 导出search列表
     */
    @PreAuthorize("@ss.hasPermi('lighthouse:doc:export')")
    @Log(title = "search", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, KnowledgeDocSearch knowledgeDocSearch)
    {
        List<KnowledgeDocSearch> list = knowledgeDocSearchService.selectKnowledgeDocSearchList(knowledgeDocSearch);
        ExcelUtil<KnowledgeDocSearch> util = new ExcelUtil<KnowledgeDocSearch>(KnowledgeDocSearch.class);
        util.exportExcel(response, list, "search数据");
    }

    /**
     * 获取search详细信息
     */
    @PreAuthorize("@ss.hasPermi('lighthouse:doc:query')")
    @GetMapping(value = "/{userId}")
    public AjaxResult getInfo(@PathVariable("userId") Long userId)
    {
        return success(knowledgeDocSearchService.selectKnowledgeDocSearchByUserId(userId));
    }

    /**
     * 新增search
     */
    @PreAuthorize("@ss.hasPermi('lighthouse:doc:add')")
    @Log(title = "search", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody KnowledgeDocSearch knowledgeDocSearch)
    {
        return toAjax(knowledgeDocSearchService.insertKnowledgeDocSearch(knowledgeDocSearch));
    }

    /**
     * 修改search
     */
    @PreAuthorize("@ss.hasPermi('lighthouse:doc:edit')")
    @Log(title = "search", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody KnowledgeDocSearch knowledgeDocSearch)
    {
        return toAjax(knowledgeDocSearchService.updateKnowledgeDocSearch(knowledgeDocSearch));
    }

    /**
     * 删除search
     */
    @PreAuthorize("@ss.hasPermi('lighthouse:doc:remove')")
    @Log(title = "search", businessType = BusinessType.DELETE)
	@DeleteMapping("/{userIds}")
    public AjaxResult remove(@PathVariable Long[] userIds)
    {
        return toAjax(knowledgeDocSearchService.deleteKnowledgeDocSearchByUserIds(userIds));
    }
}
